<%-- 
    Document   : index
    Created on : 01/10/2009, 18:29:29
    Author     : MB
--%>

<%@page import="data.FuncionarioDO"%>
<%@page import="data.UserDO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>POLIHealth, Engenheirando a Saúde - Pagina de Login</title>
    </head>
    <body>
        Sistema de Gerenciamento Hospitalar
<%  if (request.getParameter("campo_controle") != null ) {
    transacoes.User u = new transacoes.User();
    UserDO udo = new UserDO();
    String user = request.getParameter("usuario");
    String passwd = request.getParameter("senha"); 
    
    udo = u.buscarPorNome(user);
    String Pass = udo.getPassword();
    if(Pass.equals(passwd)){
        int id = udo.getIdPaciente();
            if(id != 1){
                session.setAttribute("user_name", user);
                session.setAttribute("user_ID", id);
                pageContext.forward("patient.jsp");
            }
            else{
                transacoes.Funcionario f = new transacoes.Funcionario();
                FuncionarioDO fdo = new FuncionarioDO();
                id = udo.getIdFuncionario();
                fdo = f.buscar(id);
                String tipo = new String();
                tipo = fdo.getFuncao();
                if(tipo.equals("Medico")){
                    session.setAttribute("user_name", user);
                    session.setAttribute("user_ID", id);
                    pageContext.forward("main_med.jsp");
                }
                else if(tipo.equals("Recepcionita")){
                    session.setAttribute("user_name", user);
                    session.setAttribute("user_ID", id);
                    pageContext.forward("mainRecp.jsp");
                }
                else if (tipo.equals("Enfermeira")){
                    session.setAttribute("user_name", user);
                    session.setAttribute("user_ID", id);
                    //pageContext.forward("enfermeira.jsp"); //cade?
                }
               else if (tipo.equals("Administrador")){
                    session.setAttribute("user_name", user);
                    session.setAttribute("user_ID", id);
                    //pageContext.forward("adm.jsp"); //cadê?
                }
            }
        }
        else{
%>
           Usuário ou Senha invalidos!
   <%
//        System.out.println("Usuario ou Senha invalida");
 //       return;
        }
    
%>
    <form method="post" action=index.jsp>
       Usuario <input type="text" name="usuario" />
       Senha <input type="password" name="senha" />
       <input type="submit" name="enviar" value="Enviar" />
       <input type="hidden" name="campo_controle" />
    </form>
    </body>
</html>
